#include <stdio.h>

void swapVal(int *nums, int *numSize)
{
    int swap = *nums;
    *nums = *numSize;
    *numSize = swap;
}

void selectSort(int *nums, int numSize)
{
    int minVal = 0;
    int minIndex = 0;
    for (int idx = 0; idx < numSize - 1; idx++)
    {
        minVal = nums[idx];
        for (int start = idx + 1; start < numSize; start++)
        {
            if (minVal > nums[start])
            {
                minVal = nums[start];
                minIndex = start;
            }
        }
        if (minIndex != idx)
        {
            swapVal(&(nums[idx]), &(nums[minIndex]));
        }
    }
}

void printArray(int *nums, int numSize)
{
    for (int i = 0; i < numSize; i++)
    {
        printf("%d ", nums[i]);
    }
    printf("\n");
}

int main()
{
    int str[6] = {29, 16, 26, 24, 0, 6};
    int length = sizeof(str) / sizeof(str[0]);
    selectSort(str, length);
    printArray(str, length);
    return 0;
}